﻿using System;
using System.Security.Cryptography;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Pay.DTO {
	public partial class DtoHelper {
		/// <summary>
		/// OSS的访问ID
		/// </summary>
		public const string _accessKeyId = "LTAI5YjJ5KvrD53T";
		/// <summary>
		/// OSS的访问密钥
		/// </summary>
		public const string _accessKeySecret = "UPcEmDmVvAYjOdRZwoFSrxbLjwOTmm";
#if DEBUG
		/// <summary>
		/// OSS存储空间名称
		/// </summary>
		public const string oss_bucketName = "test-sfb";
#else
		/// <summary>
		/// OSS存储空间名称
		/// </summary>
		public const string oss_bucketName = "bucket-sfb";
#endif
		/// <summary>
		/// 唯一订单号生成
		/// </summary>
		/// <returns></returns>
		public static string GenerateOrderNumber() {
			string strDateTimeNumber = DateTime.Now.ToString("yyyyMMddHHmmssms");
			string strRandomResult = RandCode(4);
			return strDateTimeNumber + strRandomResult;
		}
		/// <summary>  
		/// 根据GUID获取16位的唯一字符串  
		/// </summary>  
		/// <returns></returns>  
		public static string GuidTo16String() {
			long i = 1;
			foreach (byte b in Guid.NewGuid().ToByteArray())
				i *= ((int)b + 1);
			return string.Format("{0:x}", i - DateTime.Now.Ticks);
		}
		/// <summary>  
		/// 根据GUID获取19位的唯一数字序列  
		/// </summary>  
		/// <returns></returns>  
		public static long GuidToLongID() {
			byte[] buffer = Guid.NewGuid().ToByteArray();
			return BitConverter.ToInt64(buffer, 0);
		}
		/// <summary>
		/// 生成N位随机数 
		/// </summary>
		/// <param name="N">N位随机数</param>
		/// <returns>生成的N位随机数</returns>
		public static string RandCode(int N) {
			char[] arrChar = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
			StringBuilder num = new StringBuilder();
			Random rnd = new Random(Guid.NewGuid().GetHashCode());
			for (int i = 0; i < N; i++) {
				num.Append(arrChar[rnd.Next(0, arrChar.Length)].ToString());
			}
			return num.ToString();
		}
	}
}
